import React, { Component,Fragment } from 'react';
import { connect } from 'react-redux';
import * as actionCreators from '../../store/actionCreators';
import {API_LIST} from "../../common/js/api";

class Home extends Component {
    goToAbout() {
        this.props.history.push('/index/menu');
    }
    changeState() {
        let val = this.props.myData + 1;
        this.props.getData(val)
    }
    fetchData() {
        this.request({
            url: API_LIST.wxParams,
            params: {
                token: '111'
            },
            callback: (data) => {
                console.log(data)
            },
            error: (data) => {
                console.log(data)
            }
        })
    }
    render() {
        return (
            <Fragment>
                <h1>这里是Home</h1>
                <p>homeData:{this.props.myData}</p>
                <button onClick={() => this.changeState()}>更改</button>
                <button onClick={() => this.goToAbout()}>跳转</button>
                <button onClick={() => this.fetchData()}>发起请求</button>
            </Fragment>

        )
    }
}

const mapStateToProps = (state) => {
    return {
        myData: state.get('myData')
    }
}

const mapDispatchToProps = (dispatch) => ({
    getData(data) {
        const action = actionCreators.getData(data);
        dispatch(action);
    }
})
export default connect(mapStateToProps,mapDispatchToProps)(Home)
